#!/usr/bin/python
#coding=utf-8
import logging
import os
import sys
import datetime
import time
from CdPostGetter import CdPostGetter
from QbqPostGetter import QbqPostGetter
from SbzPostGetter import SbzPostGetter
from getImg import getImgFile
import os.path

logging.basicConfig(level=logging.DEBUG,
##									format='%(thread)d %(asctime)s %(funcName)s %(message)s',
##									format='%(asctime)s %(name)s %(levelname)s %(funcName)s %(message)s',
									format='%(funcName)s %(message)s',
                  datefmt= '%H:%M:%S')

if __name__=='__main__':
	reload(sys)
	sys.setdefaultencoding('utf-8')
	logging.info('Time Zone: %s',os.environ['TZ']) #	os.environ['TZ']='Asia/Shanghai'

	time_hour=108
	time_day=2

	qbq=QbqPostGetter(os.path.join(os.path.dirname(os.path.abspath(__file__)),'qbq_cookie.dat'))
	qbq.forum_name='qbq'
	qbq.doWork('qbq','qbq-茶馆',
##								datetime.datetime.today()-datetime.timedelta(minutes=60),
								datetime.datetime.today()-datetime.timedelta(days=time_day),
##								datetime.datetime.today()-datetime.timedelta(hours=time_hour),
								1,100)
	qbq.doWork('qbq','qbq-警务',
##								datetime.datetime.today()-datetime.timedelta(minutes=60),
								datetime.datetime.today()-datetime.timedelta(days=time_day),
##								datetime.datetime.today()-datetime.timedelta(hours=time_hour),
								1,100)

	cd=CdPostGetter(os.path.join(os.path.dirname(os.path.abspath(__file__)),'cd_cookie.dat'))
	cd.forum_name='cd'
	cd.doWork('cd','cd-生活茶馆',
##								datetime.datetime.today()-datetime.timedelta(minutes=60),
								datetime.datetime.today()-datetime.timedelta(days=time_day),
##								datetime.datetime.today()-datetime.timedelta(hours=time_hour),
								1,100)
	cd.doWork('cd','cd-中外历史(原创讨论)',
								datetime.datetime.today()-datetime.timedelta(days=time_day),
##								datetime.datetime.today()-datetime.timedelta(hours=time_hour),
								1,100)

	pg=SbzPostGetter(os.path.join(os.path.dirname(os.path.abspath(__file__)),'sbz_cookie.dat'))
	pg.forum_name='sbz'
	pg.doWork('sbz','sbz-自然科学',
##								datetime.datetime.today()-datetime.timedelta(minutes=60),
								datetime.datetime.today()-datetime.timedelta(days=time_day),
##								datetime.datetime.today()-datetime.timedelta(hours=time_hour),
##								datetime.datetime.today()-datetime.timedelta(days=3),
								1,40)
	time.sleep(1)
	pg.doWork('sbz','sbz-古代战争',
##								datetime.datetime.today()-datetime.timedelta(minutes=60),
								datetime.datetime.today()-datetime.timedelta(days=time_day),
##								datetime.datetime.today()-datetime.timedelta(hours=time_hour),
##								datetime.datetime.today()-datetime.timedelta(days=3),
								1,40)
	pg.printStat()

	o=getImgFile('','~/data_bk/bbsimgfile/')
	o.loadCfg()
	org_processed_maxid, new_processed_maxid = o.processed_maxid, 0
	o.getImageUrl('sbz','sbz-自然科学',org_processed_maxid)
	if new_processed_maxid<o.processed_maxid:
		new_processed_maxid=o.processed_maxid
	o.getImageUrl('sbz','sbz-古代战争',org_processed_maxid)
	if new_processed_maxid<o.processed_maxid:
		new_processed_maxid=o.processed_maxid
	o.processed_maxid=new_processed_maxid
	o.saveCfg()

	o.getImage(80300,None,4)

	logging.debug('done')
##	raw_input('press enter to exit ...')
